from tkinter import ON

from django.db import models


# Create your models here.
# 用户表
class User(models.Model):
    on = 1
    off = 2
    STATUS_CHOICES = {
        (on, "正常"),
        (off,"锁定")
    }
    class Meta:
        verbose_name_plural = '用户列表'
    user_name = models.CharField(max_length=30, unique=True,verbose_name="用户名")
    pwd = models.CharField(max_length=20,verbose_name="密码")
    status = models.IntegerField(verbose_name="状态",choices=STATUS_CHOICES,default=ON)
    phone = models.CharField(max_length=30, unique=True,verbose_name="手机号")

# 收货地址
class Address(models.Model):
    class Meta:
        verbose_name_plural = '收货地址'
    user = models.ForeignKey('User', on_delete=models.CASCADE)
    user_name = models.CharField(max_length=20)
    phone = models.CharField(max_length=30, unique=True)
    address = models.CharField(max_length=200, null=False)
    is_default = models.IntegerField()

#商品表
class Goods(models.Model):
    k = '克'
    j = '斤'
    g = '个'
    UNIT_CHOICES = {
        (k ,'克'),
        (j ,'斤'),
        (g ,'个')
    }
    class Meta:
        verbose_name_plural = '商品表'
    good_name = models.CharField(max_length=30)
    img_url = models.ImageField(upload_to='img')
    price = models.IntegerField()
    intro = models.TextField()
    type = models.ManyToManyField('Type')
    unit = models.CharField(max_length=30,choices=UNIT_CHOICES,default="克")

# 商品分类
class Type(models.Model):
    class Meta:
        verbose_name_plural ='商品分类'
    type_name = models.CharField(max_length=30,unique=True)
    def __str__(self):
        return self.type_name

#购物车
class Cart(models.Model):
    num = models.IntegerField()
    user = models.ForeignKey("User",on_delete=models.CASCADE)
    goods = models.ManyToManyField(Goods)

# 订单表
class Order(models.Model):
    class Meta:
        verbose_name_plural = '订单表'
    order_no = models.CharField(max_length=30,unique=True)
    status = models.IntegerField()
    time=models.DateTimeField(auto_now_add=True)
    user_name = models.CharField(max_length=20)
    phone = models.CharField(max_length=30)
    address = models.CharField(max_length=200, null=False)
    user = models.ForeignKey("User", on_delete=models.CASCADE)
    total_price = models.IntegerField()
    pay_status = models.IntegerField()

#订单详情表
class OrderDetial(models.Model):
    good_name = models.CharField(max_length=30)
    price = models.IntegerField()
    num = models.IntegerField()
    img_url = models.CharField(max_length=100)
    total_price = models.IntegerField()
    order = models.ForeignKey('Order',on_delete=models.CASCADE)